<template>
	<view>
		<view style="background-color: white;padding:20rpx;padding-bottom: 0;">
			<u-search inputAlign="center" placeholder="代驾姓名/手机号" @search="data=[];form.page=1;getData()"
				@click="data=[];getData()" v-model="form.text" :showAction="false"></u-search>
		</view>
		<view style="background-color: white;">
			<u-dropdown>
				<u-dropdown-item v-model="form.custom_type" title="代驾类型" :options="[{label:'内部员工',value:1},{label:'外部代驾',value:2}]" @change="form.page=1;data=[];getData()"></u-dropdown-item>
			</u-dropdown>
		</view>
		<view style="background-color: white;">
			<u-cell-group>
				<u-cell-item :title="item.valet_name" v-for="(item,idx) in data" :value="item.valet_tel" @click="selectItem=JSON.parse(JSON.stringify(item));show=true">
					<view slot="label" style="display: flex;justify-content: flex-start;">
						<view >
							<text v-if="item.valet_type==1">内部员工</text>
							<text v-if="item.valet_type==2">外部代驾</text>
						</view> 
						<view >
							<text v-if="item.sys_work_state==1">工作中</text>
							<text v-if="item.sys_work_state==2">下班</text>
						</view>
					</view>
				</u-cell-item>
			</u-cell-group>
		</view>
		<u-toast ref="uToast"></u-toast>
		<u-modal v-model="show" @confirm="selectSysValet" title="确定绑定吗？" :show-cancel-button="true">
			<view class="slot-content" style="padding: 30rpx;">
				<view>
					确定绑定客户【{{selectItem.valet_name}}】吗？
				</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show:false,
				selectItem:null,
				orders_id:null,
				count: 0,
				refresher: false,
				form: {
					text: '',
					page: 1,
					limit: 20,
					custom_type:''
				},
				data: []
			}
		},
		onLoad(options) {
			console.log(options);
			if(options.orders_id){
				this.orders_id=options.orders_id;
			}
		},
		mounted() {
			var that = this;
			this.getData();
			
		},
		onPullDownRefresh() {
			this.refresherpulling();
		},
		onReachBottom() {
			console.log(this.count);
			if (this.count == 0) {
				this.$refs.uToast.show({
					title: '没那么多代驾员了',
					type: "warning"
				});
				return;
			}
			this.scrolltolower();
		},
		methods: {
			selectSysValet(item){
				var that=this;
				that.selectItem.order_id=this.orders_id;
				that.$http.post('/orders/ordersBinValet', that.selectItem, (res) => {
					if (res.data.success) {
						that.$refs.uToast.show({
							title: '绑定成功',
							type: "success"
						});
						uni.$emit('getOrdersInfo',item);
						uni.navigateBack();
					} else {
						that.refs.myModal.show('请求失败', res.data.result.message);
					}
				});
				
			},
			getData() {
				var that = this;
				that.$http.post('/sysValet/ListByEntity', that.form, (res) => {
					uni.stopPullDownRefresh();
					if (res.data.success) {
						that.data = that.data.concat(res.data.result.list);
						that.count = res.data.result.list.length;
					} else {
						that.refs.myModal.show('请求失败', res.data.result.message);
					}
				});
			},
			refresherpulling(e) {
				this.form.page = 1;
				this.refresher = true;
				this.data = [];
				this.getData();
			},
			scrolltolower(e) {
				this.form.page++;
				this.getData();
			},
		}
	}
</script>

<style>

</style>